home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / util / text / proged1.lha / InstallProgED / sources / PED_APIExample / PED_API.c next >
C/C++ Source or Header  |  1995-07-27  |  6KB  |  280 lines

  1.  
  2. /******
  3.  * Include vari
  4.  ******/
  5.  
  6. #include "ProgED:sources/include/Ped.h"
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11. #include <proto/intuition.h>
  12. #include <rexx/errors.h>
  13.  
  14.  
  15.  
  16. /******
  17.  * Prototipi funzioni
  18.  ******/
  19.  
  20. LONG ASM SAVEDS CmdBeep( RG(a0) struct CommandData * );
  21. void ApriMiaFinestra( void );
  22. void ChiudiMiaFinestra( void );
  23. void SendMessageToPED( struct APIMessage * );
  24.  
  25.  
  26.  
  27. /******
  28.  * Variabili globali
  29.  ******/
  30.  
  31. struct IntuitionBase    *IntuitionBase;
  32. struct Window        *PEDWindow;
  33. struct Screen        *PEDScreen;
  34. struct MsgPort        *MyPort,
  35.             *PEDPort;
  36.  
  37. static int tre=3;
  38.  
  39. struct ArexxExtCmds    MyCmdBeep={
  40. TRUE,            /* TRUE=Comando esterno */
  41. "BEEP",            /* Nome del comando */
  42. "NUM/N,FLAG/S",        /* Template ReadArgs */
  43. {&tre,0,},        /* Vettore di default per gli argomenti */
  44. CmdBeep,        /* Funzione di gestione del comando */
  45. NULL            /* Porre a NULL e non manipolare! Grazie. *****/
  46. };
  47.  
  48. struct APIClient    MyClient={
  49. NULL,                    /* Questo campo sara' riempito dopo... */
  50. NOTIFY_ON_SHOW_HIDE|NOTIFY_ON_KEY,    /* Dimmi quando chiudi e riapri il tuo schermo e quando l'utente batte un tasto*/
  51. "prova cliente",            /* Nome del cliente (non utilizzato ancora) */
  52. NULL                    /* Porre a NULL e non manipolare! Grazie. *****/
  53. };
  54.  
  55.  
  56.  
  57. /*****
  58.  *
  59.  * FUNZIONE:    void main(void)
  60.  *
  61.  * SCOPO:    Cerca la porta API del ProgED, si registra come cliente ed
  62.  *        apre una finestra sullo schermo del ProgED. Aggiunge un
  63.  *        comando interno BEEP che, se eseguito da ProgED, il
  64.  *        solo effetto di chiamare la funzione DisplayBeep (vedi
  65.  *        la funzione CmdBeep).
  66.  *
  67.  * RESTITUISCE: -
  68.  *
  69.  ****/
  70.  
  71. void main(void)
  72. {
  73.     struct APIMessage     msg,
  74.                 *mess;
  75.     struct IntuiMessage    *imsg;
  76.     UBYTE             finito;
  77.  
  78.  
  79.  
  80.     /***** Cerca la porta del ProgED *****/
  81.     if (!(PEDPort=FindPort("PED_API")))
  82.     {
  83.         printf("Can't find ProgED API Port!\n");
  84.         exit(0);
  85.     }
  86.  
  87.     /***** Crea una porta che utilizzeremo per ricevere i msg dal ProgED *****/
  88.     if (!(MyPort=CreateMsgPort()))
  89.     {
  90.         printf("Can't create a MsgPort!\n");
  91.         exit(0);
  92.     }
  93.  
  94.     /***** Riempi il campo ac_ClientPort della struttura APIClient che
  95.         utilizzeremo per la registrazione *****/
  96.     MyClient.ac_ClientPort=MyPort;
  97.  
  98.     /***** Apri intuition.library :-)) *****/
  99.     if (!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  100.     {
  101.         DeleteMsgPort(MyPort);
  102.         printf("Can't open intuition.library!\n");
  103.         exit(0);
  104.     }
  105.  
  106.     /***** Registriamoci come cliente presso il ProgED *****/
  107.     msg.am_MsgType=PED_API_REGISTER;
  108.     msg.am_MsgArg[0]=(ULONG)&MyClient;
  109.     SendMessageToPED(&msg);
  110.  
  111.     /***** Aggiungi il comando interno BEEP *****/
  112.     msg.am_MsgType=PED_API_ADD_INTERNAL_COMMAND;
  113.     msg.am_MsgArg[0]=(ULONG)&MyCmdBeep;
  114.     SendMessageToPED(&msg);
  115.  
  116.     /***** Ottiene l'indirizzo dello schermo del ProgED *****/
  117.     msg.am_MsgType=PED_API_GET_SCREEN_ADDRESS;
  118.     SendMessageToPED(&msg);
  119.  
  120.     /***** Se e' non nullo apri una finestra. Se e' NULL ProgED e'
  121.         attualmente iconificato! In questo caso ci spedira' un
  122.         messaggio per farci sapere quando aprire la finestra. *****/
  123.     if (msg.am_RC)    ApriMiaFinestra();
  124.  
  125.     /***** Loop principale *****/
  126.     finito=FALSE;
  127.     while(!finito)
  128.     {
  129.         WaitPort(MyPort);
  130.         while(mess=(struct APIMessage *)GetMsg(MyPort))
  131.         {
  132.             switch(mess->am_MsgType)
  133.             {
  134.                 /***** ProgED sta' per terminare! Terminiamo
  135.                     anche noi :-( *****/
  136.                 case    PED_API_QUIT:
  137.                     finito=TRUE;
  138.                 break;
  139.  
  140.                 /***** ProgED sta' per chiudere il suo schermo.
  141.                     Chiudiamo la nostra finestra. *****/
  142.                 case    PED_API_HIDE:
  143.                     ChiudiMiaFinestra();
  144.                 break;
  145.  
  146.                 /***** ProgED ha riaperto il suo schermo.
  147.                     Riapriamo la nostra finestra. *****/
  148.                 case    PED_API_SHOW:
  149.                     ApriMiaFinestra();
  150.                 break;
  151.  
  152.                 /***** L'utente ha battuto il tasto RETURN *****/
  153.                 case    PED_API_KEY:
  154.                     imsg=(struct IntuiMessage *)mess->am_MsgArg[0];
  155.                     if (imsg->Code==196)    DisplayBeep(0);
  156.                 break;
  157.             }
  158.  
  159.             mess->am_RC=0;
  160.  
  161.             ReplyMsg((struct Message *)mess);
  162.         }
  163.     }
  164.  
  165.     /***** Libera tutto ed esci *****/
  166.     DeleteMsgPort(MyPort);
  167.     CloseLibrary((struct Library *)IntuitionBase);
  168.     exit(0);
  169. }
  170.  
  171.  
  172.  
  173. /*****
  174.  *
  175.  * FUNZIONE:    void ApriMiaFinestra(void)
  176.  *
  177.  * SCOPO:    Apre una finestra sullo schermo del ProgED.
  178.  *
  179.  * RESTITUISCE: -
  180.  *
  181.  ****/
  182.  
  183. void ApriMiaFinestra(void)
  184. {
  185.     PEDWindow=OpenWindowTags(NULL,
  186.         WA_Width,        100,
  187.         WA_Height,        80,
  188.         WA_Title,        "Prova !!!!!!!!",
  189.         WA_DepthGadget,        TRUE,
  190.         WA_SizeGadget,        TRUE,
  191.         WA_DragBar,        TRUE,
  192.         WA_SmartRefresh,    TRUE,
  193.         WA_PubScreenName,    "PED_SCREEN",
  194.     TAG_DONE);
  195. }
  196.  
  197.  
  198.  
  199. /*****
  200.  *
  201.  * FUNZIONE:    void ChiudiMiaFinestra(void)
  202.  *
  203.  * SCOPO:    Chiude la finestra aperta tramite ApriMiaFinestra().
  204.  *
  205.  * RESTITUISCE: -
  206.  *
  207.  ****/
  208.  
  209. void ChiudiMiaFinestra(void)
  210. {
  211.     if (PEDWindow)    CloseWindow(PEDWindow);
  212.     PEDWindow=NULL;
  213. }
  214.  
  215.  
  216.  
  217. /*****
  218.  *
  219.  * FUNZIONE:    LONG CmdBeep(struct CommandData *data)
  220.  *
  221.  * SCOPO:    Questa e' la funzione di gestione del comando BEEP.
  222.  *        Come e' possibile notare gli argomenti vengono estratti
  223.  *        dal vettore data->CommandArg[]. ProgED ha gia' provveduto
  224.  *        a chiamare la funzione ReadArgs per noi.
  225.  *
  226.  *        Questo comando effettua un singolo beep se l'utente
  227.  *        ha specificato il flag "FLAG" o "n" BEEP se l'utente
  228.  *        utilizza il comando nella forma "BEEP NUM <n>".
  229.  *
  230.  * RESTITUISCE: -
  231.  *
  232.  ****/
  233.  
  234. LONG ASM SAVEDS CmdBeep(RG(a0) struct CommandData *data)
  235. {
  236.     long    num=*((LONG *)data->CommandArgs[0]),
  237.         flag=(long)data->CommandArgs[1];
  238.     int    i;
  239.  
  240.     if (flag)
  241.     {
  242.         for(i=0;i<num;i++)
  243.         {
  244.             DisplayBeep(NULL);
  245.             Delay(50);
  246.         }
  247.     }
  248.     else    DisplayBeep(NULL);
  249.  
  250.     return(RC_OK);
  251. }
  252.  
  253.  
  254.  
  255. /*****
  256.  *
  257.  * FUNZIONE:    void SendMessageToPED(struct APIMessage    *msg)
  258.  *
  259.  * SCOPO:    Questa funzione spedisce un messaggio alla porta APi del
  260.  *        ProgED.
  261.  *
  262.  * RESTITUISCE: -
  263.  *
  264.  ****/
  265.  
  266. void SendMessageToPED(struct APIMessage    *msg)
  267. {
  268.     msg->am_Message.mn_Node.ln_Succ=NULL;
  269.     msg->am_Message.mn_Node.ln_Pred=NULL;
  270.     msg->am_Message.mn_Node.ln_Type=NT_MESSAGE;
  271.     msg->am_Message.mn_Node.ln_Pri=0;
  272.     msg->am_Message.mn_Node.ln_Name=NULL;
  273.     msg->am_Message.mn_ReplyPort=MyPort;
  274.     msg->am_Message.mn_Length=sizeof(struct APIMessage);
  275.  
  276.     PutMsg(PEDPort,(struct Message *)msg);
  277.     WaitPort(MyPort);
  278.     while(GetMsg(MyPort));
  279. }
  280.